package prefix.platform.session;

import java.io.Serializable;

import play.cache.Cache;
import prefix.platform.Constants;

import service.ActorService;

public class LoginSession implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = -2823654707138253474L;

    private long m_lastAccessedTime;

    private long m_creationTime;

    private ActorService m_actor;

    public final static int m_sessionTimeout = 15 * 60; // set it to 15 min

    public LoginSession(ActorService actor) {
        this.m_actor = actor;
        this.m_creationTime = System.currentTimeMillis();
    }

    public static LoginSession getSession(String sessionId) {
        LoginSession loginSession = Cache.get(sessionId + Constants.SESSION_AUTH_KEY) == null ? null
                : (LoginSession) Cache.get(sessionId + Constants.SESSION_AUTH_KEY);
        if (loginSession != null)
            Cache.set(sessionId + Constants.SDIRA_ACCOUNT_NAME, loginSession, m_sessionTimeout);
        return loginSession;
    }

    public long getM_lastAccessedTime() {
        return m_lastAccessedTime;
    }

    public void setM_lastAccessedTime(long m_lastAccessedTime) {
        this.m_lastAccessedTime = m_lastAccessedTime;
    }

    public long getM_creationTime() {
        return m_creationTime;
    }

    public void setM_creationTime(long m_creationTime) {
        this.m_creationTime = m_creationTime;
    }

    public ActorService getActor() {
        return m_actor;
    }

    public void setActor(ActorService actor) {
        this.m_actor = actor;
    }

}
